﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace LCTNote.Models.ViewModels
{
    class BanGhiViewModel : Model
    {
        public int ma { get; set; }
        public string noiDung { get; set; }
        public string noiDungDinhDang { get; set; }
        public List<TuKhoaViewModel> danhSachTuKhoa { get; set; }
        public DateTime thoiGianCapNhat { get; set; }
        public List<TapTinViewModel> danhSachTapTin { get; set; }
        public int maThuMuc { get; set; }
        public string tieuDe { get; set; }
        public DateTime thoiGianBao { get; set; }
        public bool Ghim { get; set; }
        public int maNguoiTao { get; set; }

        public override void assignModel(SqlDataReader dataReader)
        {
            for (int i = 0; i < dataReader.FieldCount; i++)
            {
                switch (dataReader.GetName(i))
                {
                    case "Ma":
                        ma = !dataReader.IsDBNull(i) ? dataReader.GetInt32(i) : 0; break;
                    case "NoiDung":
                        noiDung = !dataReader.IsDBNull(i) ? dataReader.GetString(i) : null; break;
                    case "NoiDungDinhDang":
                        noiDungDinhDang = !dataReader.IsDBNull(i) ? dataReader.GetString(i) : null; break;
                    case "DanhSachTuKhoa":
                        //loaiBaiViet = LoaiBaiVietService.layLoaiBaiVietTheoMaBaiViet(this.ma); 
                        break;
                    case "ThoiGianCapNhat":
                        thoiGianCapNhat = !dataReader.IsDBNull(i) ? dataReader.GetDateTime(i) : DateTime.MinValue; break;
                    case "DanhSachTapTin":
                        //loaiBaiViet = LoaiBaiVietService.layLoaiBaiVietTheoMaBaiViet(this.ma); 
                        break;
                    case "MaThuMuc":
                        maThuMuc = !dataReader.IsDBNull(i) ? dataReader.GetInt32(i) : 0; break;
                    case "TieuDe":
                        tieuDe = !dataReader.IsDBNull(i) ? dataReader.GetString(i) : null; break;
                    case "ThoiGianBao":
                        thoiGianBao = !dataReader.IsDBNull(i) ? dataReader.GetDateTime(i) : DateTime.MinValue; break;
                    case "Ghim":
                        Ghim = !dataReader.IsDBNull(i) ? dataReader.GetBoolean(i) : false; break;
                    case "MaNguoiTao":
                        maNguoiTao = !dataReader.IsDBNull(i) ? dataReader.GetInt32(i) : 0; break;
                    default:
                        break;
                }
            }
        }
    }
}
